<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Repositories\UserQuestionRepositories;
use App\User\Question;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class QuestionController extends Controller
{
    protected $repo;

    public function __construct(UserQuestionRepositories $repo)
    {
        $this->repo = $repo;
    }

    public function index()
    {
        $subject = Auth::user()->subject;
        if (!$subject) {
            return view('user.select');
        }
        $sections = $this->repo->sections($subject);
        $subject_child = $this->repo->subject($subject);
        $subject_parent = $this->repo->subject($subject_child->parent_id);
        $errors=$this->repo->errors(Auth::user()->id);
        return view('user.question', compact('sections', 'subject_child', 'subject_parent','errors'));
    }

    public function show(Request $request,$section)
    {
        $question=$this->repo->question($request);
        return view('user.question_sections',compact('question','section'));
    }
}
